package com.message.util;

import com.message.annotion.TableField;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ReflectUtil {
    public static void datafuzhi(ResultSet resultSet, Object object) {
        Field[] fields = object.getClass().getDeclaredFields();
        for (int i = 0, len = fields.length; i < len; i++) {
            TableField tableField = fields[i].getAnnotation(TableField.class);
            if (tableField != null) {
                String value = tableField.value();
                try {
                    Object object1 = resultSet.getObject(value, fields[i].getType());
                    fields[i].setAccessible(true);
                    fields[i].set(object, object1);
                } catch (SQLException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
